package red.stu.pconstraint.config;

import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import lombok.experimental.Accessors;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.Arrays;
import java.util.List;
import java.util.Properties;

/**
 * 配置信息
 *
 * @author yihrmc @stu.red
 * @date 2019/11/14 10:15
 */
@Getter
@Setter
@ToString
public class Configuration {

    public static final String SCANNER_TYPE_PACKAGE = "package";

    public static final String SCANNER_TYPE_CLASS = "class";

    @NotNull
    private Properties variables;

    @Nullable
    private List<Scanner> scannerList;

    @Nullable
    private List<Mapper> mapperList;

    public void setVariables(Properties variables) {
        if (variables == null) {
            variables = new Properties();
        }
        this.variables = variables;
    }

    @Getter
    @Setter
    @Accessors(chain = true)
    @ToString
    public static class Scanner {

        private String type;

        private String value;

//        private boolean openProcessControl;
//
//        private boolean openProcessNode;
//
//        private boolean openProcessPersistence;

    }

    @Getter
    @Setter
    @Accessors(chain = true)
    @ToString
    public static class Mapper {

        private String type;

        private String value;


        public enum Type {

            Resource("resource"),
            Resources("resources"),
            Url("url"),
            ClassName("class"),
            Unknown("");

            private String typeName;

            Type(String typeName) {
                this.typeName = typeName;
            }

            public static Type typeOf(String typeName) {
                for (Type type : Type.values()) {
                    if (typeName.equalsIgnoreCase(type.typeName)) {
                        return type;
                    }
                }
                return Unknown;
            }

        }

    }

}
